package Tree;

import java.util.ArrayList;
import java.util.List;

public class kThLargest4Tree {

   public   List<Integer> list = new ArrayList<>();


   public static void main(String[] args) {
       TreeNode root = new TreeNode(10);
       TreeNode left = new TreeNode(5);
       TreeNode left4L = new TreeNode(3);
       TreeNode right4L = new TreeNode(6);
       TreeNode right = new TreeNode(15);
       TreeNode left4R = new TreeNode(12);
       TreeNode right4R = new TreeNode(16);
       left.left = left4L;
       left.right = right4L;
       root.left = left;

       right.left = left4R;
       right.right = right4R;
       root.right = right;
       kThLargest4Tree so = new kThLargest4Tree();
       so.kthLargest(root,3);

   }




    int res, k;
    public  int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }
    void dfs(TreeNode root) {
        if(root == null) return;
        dfs(root.right);
        //System.out.println(root.val);
        if(k == 0) return;
        if(--k == 0) res = root.val;
        dfs(root.left);
    }


}
